<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for utils/index.ts</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">All files</a> / <a href="index.html">utils</a> index.ts
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">56.82% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>25/44</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">61.76% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>21/34</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">22.22% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>2/9</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">59.52% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>25/42</span>
      </div>
    </div>
  </div>
  <div class='status-line medium'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">9x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-yes">33x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">33x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">31x</span>
<span class="cline-any cline-yes">9x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">22x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">// Parse the time to string
export const parseTime = (
  time?: object | string | number,
  cFormat?: string
): string | null =&gt; {
  if (time === undefined) {
    return null
  }
  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  let date: Date
  if (typeof time === 'object') {
    date = time as Date
  } else {
    if (typeof time === 'string' &amp;&amp; /^[0-9]+$/.test(time)) {
      time = parseInt(time)
    }
    if (typeof time === 'number' &amp;&amp; time.toString().length === 10) {
      time = time * 1000
    }
    date = new Date(time)
  }
  const formatObj: { [key: string]: number } = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) =&gt; {
    let value = formatObj[key]
    // Note: getDay() returns 0 on Sunday
    if (key === 'a') {
      return ['日', '一', '二', '三', '四', '五', '六'][value]
    }
    if (result.length &gt; 0 &amp;&amp; value &lt; 10) {
      return '0' + value
    }
    return String(value) || <span class="branch-1 cbranch-no" title="branch not covered" >'0'</span>
  })
  return timeStr
}
&nbsp;
// Format and filter json data using filterKeys array
export const formatJson = <span class="fstat-no" title="function not covered" >(f</span>ilterKeys: any, jsonData: any) =&gt;
<span class="cstat-no" title="statement not covered" >  jsonData.map((<span class="fstat-no" title="function not covered" >data: any) =&gt; <span class="cstat-no" title="statement not covered" >filterKeys.map((<span class="fstat-no" title="function not covered" >key: string) =&gt; {</span></span></span></span>
<span class="cstat-no" title="statement not covered" >    if (key === 'timestamp') {</span>
<span class="cstat-no" title="statement not covered" >      return parseTime(data[key])</span>
    } else {
<span class="cstat-no" title="statement not covered" >      return data[key]</span>
    }
  }))
&nbsp;
// Check if an element has a class
export const hasClass = <span class="fstat-no" title="function not covered" >(e</span>le: HTMLElement, className: string) =&gt; {
<span class="cstat-no" title="statement not covered" >  return !!ele.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'))</span>
}
&nbsp;
// Add class to element
export const addClass = <span class="fstat-no" title="function not covered" >(e</span>le: HTMLElement, className: string) =&gt; {
<span class="cstat-no" title="statement not covered" >  if (!hasClass(ele, className)) <span class="cstat-no" title="statement not covered" >e</span>le.className += ' ' + className</span>
}
&nbsp;
// Remove class from element
export const removeClass = <span class="fstat-no" title="function not covered" >(e</span>le: HTMLElement, className: string) =&gt; {
<span class="cstat-no" title="statement not covered" >  if (hasClass(ele, className)) {</span>
    const reg = <span class="cstat-no" title="statement not covered" >new RegExp('(\\s|^)' + className + '(\\s|$)')</span>
<span class="cstat-no" title="statement not covered" >    ele.className = ele.className.replace(reg, ' ')</span>
  }
}
&nbsp;
// Toggle class for the selected element
export const toggleClass = <span class="fstat-no" title="function not covered" >(e</span>le: HTMLElement, className: string) =&gt; {
<span class="cstat-no" title="statement not covered" >  if (!ele || !className) {</span>
<span class="cstat-no" title="statement not covered" >    return</span>
  }
  let classString = <span class="cstat-no" title="statement not covered" >ele.className</span>
  const nameIndex = <span class="cstat-no" title="statement not covered" >classString.indexOf(className)</span>
<span class="cstat-no" title="statement not covered" >  if (nameIndex === -1) {</span>
<span class="cstat-no" title="statement not covered" >    classString += '' + className</span>
  } else {
<span class="cstat-no" title="statement not covered" >    classString =</span>
      classString.substr(0, nameIndex) +
      classString.substr(nameIndex + className.length)
  }
<span class="cstat-no" title="statement not covered" >  ele.className = classString</span>
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Aug 05 2019 17:01:25 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
